package redis

import (
	"context"
	"encoding/json"
	"github.com/redis/go-redis/v9"
	"week_three/car_srv/common/global"
	"week_three/car_srv/models"
)

func CreateCar(car *models.Car) error {
	key := "car_price_top:"
	mar, _ := json.Marshal(car)
	return global.RedisClient.ZAdd(context.Background(), key, redis.Z{
		Score:  float64(car.Price),
		Member: mar,
	}).Err()
}
func IsCarPriceKey() int64 {
	key := "car_price_top:"
	return global.RedisClient.Exists(context.Background(), key).Val()
}
func SearchCarTop() []string {
	key := "car_price_top:"
	return global.RedisClient.ZRange(context.Background(), key, 0, -1).Val()
}
